﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class ModifyReward : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—悬赏招聘：悬赏职位查看、修改  {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_reward_id"] != null)
                {
                    if (Session["enterprise_name"] != null)
                    {
                        this.lbl_title.Text = " " + Session["enterprise_name"].ToString();
                    }


                    int enterprise_reward_id = Convert.ToInt32(Session["enterprise_reward_id"]);

                    ShowInfo(enterprise_reward_id);
                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (Session["enterprise_reward_id"] != null)
            {
                int enterprise_reward_id = Convert.ToInt32(Session["enterprise_reward_id"]);

                Save(enterprise_reward_id);
            }
        }

        private void ShowInfo(int enterprise_reward_id)
        {
            lcmyjobs.BLL.enterprise_reward bll = new lcmyjobs.BLL.enterprise_reward();
            lcmyjobs.Model.enterprise_reward model = bll.GetModel(enterprise_reward_id);

            this.txtprice.Text = model.price.ToString();
            this.txtreleasetime.Text = model.releasetime.ToString();
            this.txtrtime.Text = model.rtime.ToString();
            this.txtjobsname.Text = model.jobsname;
            this.hid_rid.Value = model.enterprise_rid.ToString();
            this.hid_issuccess.Value = model.issuccess.ToString();
            this.hid_status.Value = model.status.ToString();
            this.hid_enterprise_bh.Value = model.enterprise_bh;


        }

        private void Save(int enterprise_reward_id)
        {
            //int enterprise_reward_id = int.Parse(this.lblenterprise_reward_id.Text);
            int enterprise_rid = int.Parse(this.hid_rid.Value);
            string enterprise_bh = this.hid_enterprise_bh.Value;
            decimal price = decimal.Parse(this.txtprice.Text);
            DateTime releasetime = DateTime.Parse(this.txtreleasetime.Text);
            int rtime = int.Parse(this.txtrtime.Text);
            bool issuccess = Convert.ToBoolean(this.hid_issuccess.Value);
            int status = int.Parse(this.hid_status.Value);


            lcmyjobs.Model.enterprise_reward model = new lcmyjobs.Model.enterprise_reward();
            model.enterprise_reward_id = enterprise_reward_id;
            model.enterprise_rid = enterprise_rid;
            model.enterprise_bh = enterprise_bh;
            model.price = price;
            model.releasetime = releasetime;
            model.rtime = rtime;
            model.issuccess = issuccess;
            model.status = status;

            lcmyjobs.BLL.enterprise_reward bll = new lcmyjobs.BLL.enterprise_reward();
            if (bll.Update(model))
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "修改成功！", "ListReward.html");
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "修改失败！", "ListReward.html");
            }

        }

    }
}